
$(function () {
	setTimeout(function(){
		basics.indexMenu();
		$('[data-animation]').each(function(){
			var elem = $(this);
			elem.removeClass('not-animated').removeAttr('data-animation-delay data-animation');
		});	
	},1000);
	
});

//主页菜单
basics.indexMenu = function (){ 
	if(store.session.has('basicsMenu')){
		var arr = store.session.get('basicsMenu'); 
		basics.setIndexMenuHtml(arr,"#indexMenuBox");
		basics.initSideMenu();
		basics.hideLoading();
	} else {
		$.ajax({
			url: "/portal/index/getServiceList",
			type: "get",
			success: function (res) {
				if (res.code == 0) {
					var arr = res.data;
					store.session.set('basicsMenu', arr);
					basics.setIndexMenuHtml(arr,"#indexMenuBox");
					basics.initSideMenu();
				} else {
					 x.miniAlert('fail',res.msg,1500)
				}
			}
		});
	}
};

basics.hideLoading= function(){
	if(store.session.has('basicsMenu')){
		$("#homeLoading").hide();
	}else{
		setTimeout(function(){
			$("#homeLoading").hide();
		},1000)
	}
}

//设置主页菜单
basics.setIndexMenuHtml=function(arr,id){
	var html = "";
	if(arr.length>0){
		$.each(arr, function(i, v) {
			html += '<li >';
			html += '     <a href="/portal/service?serviceId=' + v.id + '&menuId='+v.linkMenuId+'"  data-menuId="'+v.linkMenuId+'"  data-id="'+v.id+'" data-type="'+v.serviceType+'">';
			html += '         <div class="home-item">';
			html += '             <div class="ico-item">';
			html += '				<span class="'+v.icon+'-home icon-home"></span>';
			html += '             </div>';
			html += '             <div class="className">'+v.name+'</div>';
			html += '             <div class="classSubName">';
			if(v.meuns.length>0){
				$.each(v.meuns, function(s, n) {
					html += '   <p>'+n.name+'</p>';
				})
			}else{
				html += '   <p>......</p>';
			}
			
			html += '             </div>';
			html += '         </div>';
			html += '     </a>';
			html += '</li>';
		});
	}else{
		html += '   <p class="no-menu">您目前没有该平台的任何操作权限，如有需要请联系当前健管机构管理员</p>';
	}
    $(id).empty().html(html);
    
    basics.setSideMenuScrollIndex("#silderMenuBox");
};

basics.setSideMenuScrollIndex=function(id){
	var i = $(id+" li.cur").index();
	var t = $('.silder').scrollTop();
		var silderTops = t + $('.icon-sideMenu').eq(i).offset().top - $('.silder').height()/2 + $('.icon-sideMenu').height()*0.5;
	$('.silder').stop().animate({
			scrollTop: silderTops
	}, 0);
}


